<?php include '../../authorization_check.php' ?>
<?php include '../../checkSecretaryOnly.php' ?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-9">
<title>View Course Enrollment Numbers</title>
<SCRIPT TYPE="text/javascript" src= "../../commonutils/util/util.js"> </SCRIPT>

</head>
<style type="text/css">
/* th {text-align: right} */
</style>
<body>

<?php include 'top.html' ?>

<?php include 'notifier.php' ?>
  
<FORM NAME ="form1" METHOD ="POST" ACTION = "ViewCourseEnrollmentNumbers.php">


<p>
<?php
require_once '../../commonutils/db/DBConnectionManager.php';

if (isset($_POST['btnSubmitCode']))
{
	
	$courseCode = $_POST['groupCourseCode'];
	$sqlquery = " select course.courseCode, course.courseName, section.sectionNumber, count(enrollment.studentID) as cnt".
				" from course, section left outer join enrollment on section.sectionID = enrollment.sectionID ". 
				" where course.courseCode = ".$courseCode." and section.courseCode = course.courseCode".
				" and section.semesterID = ".$semesterID." and course.programCode = ".$programCode.
				" group by section.courseCode, course.courseName, section.sectionNumber" ;
	 
	/* echo $sqlquery."<br>";  */
	
	echo "<table cellpadding=5>";
	echo "<tr>";
	echo "<td>";
	echo "<table border=1>";
	echo "<tr>";
	echo "<th>COURSE CODE </th>";
	echo "<th>COURSE NAME </th>";
	echo "<th>SECTION </th>";
	echo "<th># OF REGISTERED STUDENTS</th>";
	echo "</tr>";
	$result = DBConnectionManager::query($sqlquery);
	while($row = mysql_fetch_assoc($result)){
		echo "<tr>";
		echo "<td>".$row['courseCode']."</td>";
		echo "<td>".$row['courseName']."</td>";
		echo "<td>".$row['sectionNumber']."</td>";
		echo "<td>".$row['cnt']."</td>";
		echo "</tr>";		
	}
	echo "</table>";
	echo "</td>";
	echo "<td>";
	echo "<p>";
	echo "<input type=\"submit\" value=\" Back \" name=\"btnBack\">";
	echo "</p>";
	echo "</td>";
	echo "</tr>";
	echo "</table>";
	

	
}
else{
	echo "<p>Select the course to see the enrollment numbers of its sections:</p>";
	$sqlquery = " select course.courseCode, course.courseName ".
				" from course, section ".
				" where course.courseCode = section.courseCode and course.programCode = ".$programCode.
				" group by course.courseCode, course.courseName ";
	
	/* echo $sqlquery; */
	echo "<table cellpadding=5>";
	echo "<tr>";
	echo "<td>";
	echo "<table border=1>";
	echo "<tr>";
	echo "<th>COURSE CODE </th>";
	echo "<th>COURSE NAME </th>";	
	echo "</tr>";
	
	$result = DBConnectionManager::query($sqlquery);
	while($row = mysql_fetch_assoc($result)){
		echo "<tr>";
		echo "<td> <input type=\"radio\" name=\"groupCourseCode\" value= \"".$row['courseCode']."\"> ";
		echo " ".$row['courseCode']."</td>";
		echo "<td>".$row['courseName']."</td>";

		echo "</tr>";		
	}
	echo "</table>";
	echo "</td>";
	echo "<td>";

	echo "<p>";
	echo "<input type=\"submit\" value=\"View selected course sections\" name=\"btnSubmitCode\" ".
		 " onClick=\"return radioControl(groupCourseCode)\">";

	echo "</p>";	
	echo "</td>";
	echo "</tr>";
	echo "</table>";	
	
}

?>
</p>  
</FORM>
<?php include 'bottom.php' ?>
</body>


</html>